package co.droidforum.foodx.activities.commons;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import co.droidforum.foodx.R;
import co.droidforum.foodx.utils.DroidGallery;

public class PreingresoUserActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.preingreso_user);
		
		//Inicio de la galeria
		DroidGallery gallery = (DroidGallery)findViewById(R.id.galleryPreLogin);
	    gallery.setAdapter(new ImageAdapter(this));
	    gallery.setSpacing(0);
	    
	    //Botones pantalla de preingreso
	    Button buttonIngresoRegistroConEmail = (Button)findViewById(R.id.buttonIngresoRegistroConEmail);
	    buttonIngresoRegistroConEmail.getBackground().setColorFilter(0xFFFF9701, PorterDuff.Mode.MULTIPLY);
	    Button buttonIngresoEntrar = (Button)findViewById(R.id.buttonIngresoEntrar);
	    
	    buttonIngresoRegistroConEmail.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(PreingresoUserActivity.this, RegistroActivity.class);
				startActivity(intent);
			}
		});
	    
	    buttonIngresoEntrar.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(PreingresoUserActivity.this, IngresoActivity.class);
				startActivity(intent);
			}
		});
	}
	
	public class ImageAdapter extends BaseAdapter {
	    private Context mContext;
	    private Integer[] mImageIds = {
	    		R.drawable.background_app,
	    		R.drawable.carrusel_1,
	    		R.drawable.carrusel_2
//	            R.drawable.imagegalery_potencialice,
//	            R.drawable.imagegalery_acceso,
//	            R.drawable.imagegalery_nfc
	    };

	    public ImageAdapter(Context c) {
	        mContext = c;
	        TypedArray a = obtainStyledAttributes(R.styleable.galleryLogin);
	        a.recycle();
	    }

	    public int getCount() {
	        return mImageIds.length;
	    }

	    public Object getItem(int position) {
	        return position;
	    }

	    public long getItemId(int position) {
	        return position;
	    }
	    
	   
	    public View getView(int position, View convertView, ViewGroup parent) {
	        ImageView i = new ImageView(mContext);

	        i.setImageResource(mImageIds[position]);
	        
	        //i.setLayoutParams(new Gallery.LayoutParams(450, 550));
	        i.setScaleType(ImageView.ScaleType.FIT_XY);
	        
	        i.setHorizontalScrollBarEnabled(true);        

	        return i;
	    }

	}
}
